package com.example.superoa.controller;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.SalaryCount;
import com.example.superoa.model.pojos.SalaryItem;
import com.example.superoa.model.service.ItemsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class ItemsController {
	@Autowired
	private ItemsService is;
	@RequestMapping("salary-item")
	public void test1() {
		
	}
	@RequestMapping("show-items")
	@ResponseBody
	public Map<String,Object> showitmes(int page,int rows) {
		Map<String,Object> map = new HashMap<>();
		Page<Object> pg = PageHelper.startPage(page,rows);
		JSONArray i = is.showItems();
		map.put("total", pg.getTotal());
		map.put("rows", i);
		return map;
	}
	
	@RequestMapping("find-itemsname")
	@ResponseBody
	public Map<String,Object> findname(String items_name,int page,int rows) {
		Map<String,Object> map = new HashMap<>();
		Page<Object> pg = PageHelper.startPage(page,rows);
		JSONArray i = is.findname(items_name);
		map.put("total", pg.getTotal());
		map.put("rows", i);
		return map;
	}
	@RequestMapping("find-item")
	@ResponseBody
	public JSONArray findnames() {		
		return is.showItems();
	}
	//新增
	@PostMapping("xz-items")
	public String show(SalaryItem si,SalaryCount sc) {
		is.xzitems(si,sc);
		return "redirect:main-administrator:salary-item";
	}
	//编辑
	@PostMapping("bianji-items")
	@ResponseBody
	public void bianji(int items_id,int count_id,String items_name,String items_type,String items_sm,BigDecimal sc_formula,String sc_explain,String sc_danwei) {
		is.bianji(items_id, count_id,items_name, items_type, items_sm,sc_formula,sc_explain,sc_danwei);
	}
	//初始化
	@RequestMapping("show-all")
	@ResponseBody
	public JSONArray alls(int items_id) {		 		
		return is.selectid(items_id);
	}
	//删除
	@RequestMapping("delect-items")
	@ResponseBody
	public void shanchui(int items_id) {
		is.delect(items_id);
	}
}
